package com.tjnmt.togo.utils;

import android.os.Handler;

/**
 * 判断线程的工具类。
 */
public class ThreadUtil {
    private static int mainThreadId;
    private static Handler handler;
    static {
        mainThreadId=ApplicationUtils.getMainThreadId();
        handler=ApplicationUtils.getHandler();
    }
    public static boolean isRunOnUIThread(){
        int myTid=android.os.Process.myTid();
        if (myTid==mainThreadId){
            return true;
        }
        return false;
    }

    public static void runOnUiThread(Runnable runnable){
        if (isRunOnUIThread()){
            runnable.run();
        }else {
            handler.post(runnable);
        }
    }
}
